package com.easylinkin.linkappapi.operatelog.controller;


import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.operatelog.entity.VisitPrivilegeLog;
import com.easylinkin.linkappapi.operatelog.service.VisitPrivilegeLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * <p>
 * 访问菜单日志 前端控制器
 * </p>
 *
 * @author Xiaoyang
 * @since 2022-11-23
 */
@Api(tags = "访问菜单日志")
@RestController
@RequestMapping("/operatelog/visitPrivilegeLog")
public class VisitPrivilegeLogController {

  @Resource
  private VisitPrivilegeLogService visitPrivilegeLogService;

  @PostMapping
  @ApiOperation("访问记录日志")
  public RestMessage visit(@RequestBody VisitPrivilegeLog visitPrivilegeLog) {
    // 参数验证
    Assert.notNull(visitPrivilegeLog, "参数为空");
    Assert.notNull(visitPrivilegeLog.getPrivilegeCode(), "PrivilegeCode参数为空");
//    Assert.notNull(visitPrivilegeLog.getName(), "name参数为空");
    Assert.notNull(visitPrivilegeLog.getUrl(), "url参数为空");
    return RestBuilders.successBuilder(visitPrivilegeLogService.add(visitPrivilegeLog)).build();
  }

  @PostMapping("getPage")
  @ApiOperation("访问记录日志列表")
  public RestMessage getPage(@RequestBody RequestModel<VisitPrivilegeLog> requestModel) {
    Assert.notNull(requestModel, "参数为空");
    Assert.notNull(requestModel.getPage(), "参数page为空");
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams参数为空");
    return RestBuilders.successBuilder().data(visitPrivilegeLogService
        .getPage(requestModel.getPage(), requestModel.getCustomQueryParams())).build();

  }

}
